package org.example.project.bookstore.listener;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.example.bean.Order;
import org.example.bean.RocketMQOrder;
import org.example.project.bookstore.service.OrderService;
import org.springframework.stereotype.Component;

/**
 * @Auther:Liu
 * @Testname:OrderSuccessOrderLinstener
 * @Date:2025/8/27 10:09
 */
@Component
@Slf4j
@RocketMQMessageListener(consumerGroup = "order_success_2",topic = "order",selectorExpression = "transaction",messageModel = MessageModel.BROADCASTING)
public class OrderSuccessOrderLinstener implements RocketMQListener<String> {
    @Resource
    private OrderService orderService;
    @Override
    public void onMessage(String s) {
        log.info("开始执行成功操作,开始修改订单状态");
        RocketMQOrder rocketMQOrder = JSON.parseObject(s, RocketMQOrder.class);
        log.info("rocketMQOrder数据为:{}",rocketMQOrder);
        UpdateWrapper<Order> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", rocketMQOrder.getOrderId());
        updateWrapper.eq("status", 2);
        updateWrapper.set("status", 3);
        orderService.update(updateWrapper);
    }
}
